// align images to center
function alignCenter(obj){
	$(obj).each(function(){
		var currentHtml = $(this).parent().html();	
		$(this).parent().html('<table cellspacing="0" cellpadding="0" border="0" style="width:100%; height:100%; border-collapse:separate; border-spacing:0;"><tbody><tr><td align="center">' + currentHtml + '</td></tr></tbody></table>');
	});
}

// Preview product details
function objectPreview(){
	$(".basket pre").each(function(index, domEle){
		ob	= $(domEle).parent().find(".thumbnail");
		var img	= $(domEle).parent().find(".thumbnail img");
		ob.tooltip({
			bodyHandler: function(){
				//tooltipWidth	= (typeof(ob.attr("tooltipWidth")) != "undefined" ? ob.attr("tooltipWidth") : 400);
				//$("#tooltip").css("width", tooltipWidth + "px");
				$("#tooltip").css("width", "auto");
				$(domEle).find(".picture").html(function(index, html){
					width			= (typeof($(this).attr("width"))	!= "undefined" ? $(this).attr("width") : img.width());
					height		= (typeof($(this).attr("height"))!= "undefined" ? $(this).attr("height") : img.height());
					maxWidth		= (typeof($(this).attr("maxWidth"))	!= "undefined" ? $(this).attr("maxWidth") : 300);
					maxHeight	= (typeof($(this).attr("maxHeight"))!= "undefined" ? $(this).attr("maxHeight") : 200);
					arrFixSize	= fixImageSize(width, height, maxWidth, maxHeight);
					return '<img width="' + arrFixSize[0] + '" height="' + arrFixSize[1] + '" src="' + $(this).attr("rel") + '" />';
				});
				return $(domEle).html();
			},
			track: true,
			showURL: false,
			extraClass: "tooltip_product"
		});
	});
}

// Watermark
$.fn.watermark = function(){
	this.each(function(){
		var wm = $(this).attr('alt');
		var val = jQuery.trim($(this).val());
		
		if (val == '' || val == wm){
			$(this).val(wm);
			$(this).addClass('wm-on');
		}
		
		$(this).unbind();
		
		$(this).focusin(function(){
			if (wm == $(this).val()) $(this).val('');
			$(this).removeClass('wm-on');
			$(this).select();
		});
		
		$(this).focusout(function(){
			var val = $(this).val();
			if (jQuery.trim(val) == ''){
				$(this).toggleClass('wm-on');
				$(this).val(wm);
			}
		});
	});
};

$(document).ready(function(){
	// Navigation
	$("#navigation ul li").hover(
		function(){
			$(this).addClass("hover");
			$("div.subNavi:first", this).css("visibility", "visible");
		},
		function(){
			$(this).removeClass("hover");
			$("div.subNavi:first", this).css("visibility", "hidden");
		}
	);
	//$("#navigation ul li ul li:has(ul)").find("a:first").addClass("parent");

	// Watermark
	$('input.watermark').watermark();
	
	$(".productList .objListing .pane").jCarouselLite({
		visible: 5,
		easing: "easeOutSine",
		auto: 3000,
		speed: 1000,
		circular: true
	});
	
	$(".special .objListing .pane").jCarouselLite({
		vertical: true,
		visible: 1,
		easing: "easeOutSine",
		auto: 4500,
		speed: 3000,
		circular: true
	});
	
});
